/***************************************************************************
 创建者: 华磊
 开始时间: 2020.8.14
 copyright: (C) 深圳市华友高科有限公司
 修改说明: (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 example (1) hualei 2020.5.8 类的具体实现代码编写

 ***************************************************************************/
#include "mapdelegate.h"
//#include "mapview.h"
#include "../CommunicateDelegate/communicatenormaldelegate.h"
#include "../CommunicateDelegate/communicateupdatedelegate.h"

MapDelegate::MapDelegate(CommunicateNormalDelegate *communicateNormalIn, GlobalData *globalDataIn, CommunicateUpdateDelegate *communicateUpdateIn)
{
    communicateNormal=communicateNormalIn;
    communicateUpdate=communicateUpdateIn;
    globalData=globalDataIn;

//    mapView=mapViewIn;
    isDisplayAllReferenceMarks=false;
    isDisplayDetectedLaserPoints=false;
    isDisplayCalculatedReferenceMarks=false;

}

int MapDelegate::getAmclDebugInfo(AmclDebugInfo &debugInfoOut)
{
    return communicateNormal->getAmclDebugInfo(debugInfoOut);
}

int MapDelegate::getMapPropertyInfo(std::string mapName, MapPropertyInfo &infoOut)
{
    return communicateNormal->getMapPropertyInfo(mapName,infoOut);
}

GlobalData *MapDelegate::getGlobalData()
{
    return globalData;
}

CommunicateNormalDelegate *MapDelegate::getDelegate()
{
    return communicateNormal;
}

int MapDelegate::getFleetMap(std::string mapName, std::string &mapInfoReturn)
{
    return communicateNormal->getFleetMap(mapName,mapInfoReturn);
}

int MapDelegate::writeFleetMap(std::string mapName, std::string &mapInfoIn)
{
    return communicateNormal->writeFleetMap(mapName,mapInfoIn);
}

void MapDelegate::cleanAllMessage()
{
    return communicateNormal->cleanAllMsgSlot();
}

int MapDelegate::setAllManualServon(int nServOffOn, int &returnFlag)
{
    return communicateNormal->setAllManualServon(nServOffOn,returnFlag);
}

bool MapDelegate::isUseFtpStatus()
{
    return globalData->isUseFtpOrNfs;

}

int MapDelegate::setUpdatePointCloud(bool isEnable)
{
    return globalData->setUpdatePointCloud(isEnable);
}

bool MapDelegate::get_isDisplayAllReferenceMarks()
{
    return isDisplayAllReferenceMarks;
}

bool MapDelegate::get_isDisplayCalculatedReferenceMarks()
{
    return isDisplayCalculatedReferenceMarks;
}

bool MapDelegate::get_isDisplayDetectedLaserPoints()
{
    return isDisplayDetectedLaserPoints;
}

int MapDelegate::setDisplayAllReferenceMarks(bool isDisplay)
{
    isDisplayAllReferenceMarks=isDisplay;
    return 1;
}

int MapDelegate::setDisplayCalculatedReferenceMarks(bool isDisplay)
{
    isDisplayCalculatedReferenceMarks=isDisplay;
    return 1;
}

int MapDelegate::setDisplayDetectedLaserPoints(bool isDisplay)
{
    isDisplayDetectedLaserPoints=isDisplay;
    return 1;
}

int MapDelegate::getAllReferenceMarks(std::vector<ReflectMarkInfo> &reflectMarksOut)
{
    return communicateNormal->getAllReferenceMarks(reflectMarksOut);

}

int MapDelegate::addReferenceMarkToMap(ReflectMarkInfo markIn, int &returnFlag)
{
    return communicateNormal->addReferenceMarkToMap(markIn,returnFlag);
}

int MapDelegate::saveReferenceMarkToFile(std::string fileNameIn, int &returnFlag)
{
    return communicateNormal->saveReferenceMarkToFile(fileNameIn,returnFlag);
}

int MapDelegate::deleteReferenceMarkInMap(int uniqId, int &returnFlag)
{
    return communicateNormal->deleteReferenceMarkInMap(uniqId,returnFlag);
}

int MapDelegate::getReflectDebugInfo(ReflectDebugInfo &matchDebugInfoOut)
{
    return communicateNormal->getReflectDebugInfo(matchDebugInfoOut);
}

int MapDelegate::setOriginalLaserFilterType(int typeIn, int &returnFlag)
{
    return communicateNormal->setOriginalLaserFilterType(typeIn,returnFlag);
}

int MapDelegate::getMotionEngineStatus()
{
    return globalData->globalCurrentState_motion;
}

int MapDelegate::getHandControlType()
{
    return globalData->globalHandState;
}

int MapDelegate::getServoStatus()
{
    return globalData->globalServoState;
}

int MapDelegate::setDefaultMapName(std::string fileNameIn, int &returnFlag)
{
    return communicateNormal->setDefaultMapName(fileNameIn,returnFlag);
}

int MapDelegate::setCheckVehiclePosition_amcl(bool isCheck, int &returnFlag)
{
    return communicateNormal->setCheckVehiclePosition_amcl(isCheck,returnFlag);

}

int MapDelegate::setLaserIntensityFilterByType_visionMatch(int typeIn, int &returnFlag)
{
    return communicateNormal->setLaserIntensityFilterByType_visionMatch(typeIn,returnFlag);
}

int MapDelegate::setUltrasonicSensorCheckEnable(bool isOn, int &returnFlag)
{
    return communicateNormal->setUltrasonicSensorCheckEnable(isOn,returnFlag);
}

int MapDelegate::setPointCloudCheckEnable(bool isOn, int &returnFlag)
{
    return communicateNormal->setPointCloudCheckEnable(isOn,returnFlag);
}

int MapDelegate::moveToNavgationPoint(MovingToNavagationParameter parameterIn, int &returnFlag)
{
    return communicateNormal->moveToNavgationPoint(parameterIn,returnFlag);
}

int MapDelegate::getVehiclePositionInQRcode(PositionInfo_hmi &positionReturn)
{
//    globalData->lock();
    positionReturn=globalData->vehicleInQrcode;
//    globalData->unlock();
    return 1;
}

int MapDelegate::getVehiclePositionInCU1(PositionInfo_hmi &positionReturn)
{
//    globalData->lock();
    positionReturn=globalData->vehicleInCU1;
//    globalData->unlock();
    return 1;
}

int MapDelegate::getVehiclePositionInVmark(PositionInfo_hmi &positionReturn)
{
//    globalData->lock();
    positionReturn=globalData->vehicleInVmark;
//    globalData->unlock();
    return 1;
}

int MapDelegate::getVehiclePositionInWorld(PositionInfo_hmi &positionReturn)
{
//    globalData->lock();
    positionReturn=globalData->vehicleInWorld;
//    globalData->unlock();
    return 1;
}

int MapDelegate::setCurrentVMarkIndex(int indexIn, int &returnFlag)
{
    return communicateNormal->setCurrentVMarkIndex(indexIn,returnFlag);
}

int MapDelegate::setCurrentVMarkType(int currentVmarkTypeIn, int &returnFlag)
{
    return communicateNormal->setCurrentVMarkType(currentVmarkTypeIn,returnFlag);
}

int MapDelegate::getVmarkInfoList(std::vector<VMarkInfo> &vmarkInfoOut)
{
    return communicateNormal->getVmarkInfoList(vmarkInfoOut);
}

int MapDelegate::updateVMarkFile(std::string vmarkFileIn, int &returnFlag)
{
    return communicateNormal->updateVMarkFile(vmarkFileIn,returnFlag);
}


int MapDelegate::createVMark(VMarkInfo infoIn, std::string vmarkFileIn, int &returnFlag)
{
    return communicateNormal->createVMark(infoIn,vmarkFileIn,returnFlag);
}

int MapDelegate::getVMarkPositionInWorld(PositionInfo_hmi &positionReturn)
{
//    globalData->lock();
    positionReturn=globalData->vmarkInWorld;
//    globalData->unlock();
    return 1;
}


int MapDelegate::getMatchDebugInfo_vmark(VisionMatchDebugInfo &infoOut)
{
    return communicateNormal->getMatchDebugInfo_vmark(infoOut);
}

int MapDelegate::getQrcodeDebugInfo(QrcodeDebugInfo &infoOut)
{
    return communicateNormal->getQrcodeDebugInfo(infoOut);
}


//int MapDelegate::setLaserFilterByType_vmark(int typeIn, int &returnFlag)
//{
//    return communicateNormal->setLaserFilterByType_vmark(typeIn,returnFlag);
//}


QString MapDelegate::getDefaultMapName()
{
    QString tmpStr;
    return tmpStr;
}

//int MapDelegate::updateCarPosition(double x, double y, double a)
//{
//    mapView->setVehiclePosition(x,y,a);
//    //    mapView->drawCar(x,y,a);
//}





int MapDelegate::vehicleJog(double xMove, double yMove, double rotate, int &returnFlag)
{
    return communicateNormal->vehicleJog(xMove,yMove,rotate,returnFlag);
}

int MapDelegate::setMapSolver(E_MAP_SOLVER solverIn, int laserCount, int &returnFlag)
{
    return communicateNormal->setMapSolver(solverIn,laserCount,returnFlag);
}

int MapDelegate::createMapStart(int &returnFlag)
{
    return communicateNormal->createMapStart(returnFlag);
}

int MapDelegate::createMapEnd(std::string mapName, int &returnFlag)
{
    return communicateNormal->createMapEnd(mapName,returnFlag);
}

int MapDelegate::loadMap(std::string mapName, int &returnFlag)
{
    return communicateNormal->loadMap(mapName,returnFlag);
}

int MapDelegate::deleteMap(std::string mapName, int &returnFlag)
{
    return communicateNormal->deleteMap(mapName,returnFlag);
}

int MapDelegate::addVitrualBlock(std::string configFilePath, int &returnFlag)
{
    return communicateNormal->addVitrualBlock(configFilePath,returnFlag);
}

int MapDelegate::deleteVitrualBlock(int &returnFlag)
{
    return communicateNormal->deleteVitrualBlock(returnFlag);
}

int MapDelegate::addForbidenZone(double x_start, double y_start, double x_end, double y_end, int &returnFlag)
{
    return communicateNormal->addForbidenZone(x_start,y_start,x_end,y_end,returnFlag);
}

int MapDelegate::setOdomSolver(E_ODOM_SOLVER solverIn, int &returnFlag)
{
    return communicateNormal->setOdomSolver(solverIn,returnFlag);
}

int MapDelegate::setLocationSolver(E_LOCATION_SOLVER solverIn, int &returnFlag)
{
    return communicateNormal->setLocationSolver(solverIn,returnFlag);
}

//int MapDelegate::getVehiclePosition(VehiclePosition &positionReturn)
//{
//    return communicateNormal->getVehiclePosition(positionReturn);
//}

int MapDelegate::setVehiclePosition(VehiclePosition positionIn, int &returnFlag)
{
    return communicateNormal->setVehiclePosition(positionIn,returnFlag);
}

int MapDelegate::setReplanCoutLimitWhenFailure(int countLimit, int &returnFlag)
{
    return communicateNormal->setReplanCoutLimitWhenFailure(countLimit,returnFlag);
}

int MapDelegate::setTrajectoryGlobalPlanSolver(E_TRAJECTORY_GLOBAL_SOLVER solverIn, int &returnFlag)
{
    return communicateNormal->setTrajectoryGlobalPlanSolver(solverIn,returnFlag);
}

int MapDelegate::setTrajectoryLocalPlanSolver(E_TRAJECTORY_LOCAL_SOLVER solverIn, int &returnFlag)
{
    return communicateNormal->setTrajectoryLocalPlanSolver(solverIn,returnFlag);
}

int MapDelegate::moveToPosition(VehiclePosition positionIn, double velocity, int &returnFlag)
{
    return communicateNormal->moveToPosition(positionIn,velocity,returnFlag);
}

int MapDelegate::moveFollowPath(std::vector<VehiclePosition> pathIn, double velocity, int &returnFlag)
{
    return communicateNormal->moveFollowPath(pathIn,velocity,returnFlag);
}

int MapDelegate::changeVelocity(double velocity, int &returnFlag)
{
    return communicateNormal->changeVelocity(velocity,returnFlag);
}

int MapDelegate::getMovingStatus(E_GOAL_STATUS &status)
{
    return communicateNormal->getMovingStatus(status);
}

int MapDelegate::getRemainningTime(double &timeOut)
{
    return communicateNormal->getRemainningTime(timeOut);
}

int MapDelegate::getRemainningDistance(double &distanceOut)
{
    return communicateNormal->getRemainningDistance(distanceOut);
}

int MapDelegate::ceaseMotion(int &returnFlag)
{
    return communicateNormal->ceaseMotion(returnFlag);
}

int MapDelegate::startMotion(int &returnFlag)
{
    return communicateNormal->startMotion(returnFlag);
}

int MapDelegate::cancelMotion(int &returnFlag)
{
    return communicateNormal->cancelMotion(returnFlag);
}

int MapDelegate::setPositionArrivedAccuracy(double accuracyIn, int &returnFlag)
{
    return communicateNormal->setPositionArrivedAccuracy(accuracyIn,returnFlag);
}

int MapDelegate::setLocalPlanRange(double rangeIn, int &returnFlag)
{
    return communicateNormal->setLocalPlanRange(rangeIn,returnFlag);
}

int MapDelegate::setVehicleBorderOffset(std::vector<double> point_x, std::vector<double> point_y, int &returnFlag)
{
    return communicateNormal->setVehicleBorderOffset(point_x,point_y,returnFlag);
}

int MapDelegate::setGlobalBarrierOffset(double offsetIn, int &returnFlag)
{
    return communicateNormal->setGlobalBarrierOffset(offsetIn,returnFlag);
}

int MapDelegate::setLocalBarrierOffset(double offsetIn, int &returnFlag)
{
    return communicateNormal->setLocalBarrierOffset(offsetIn,returnFlag);
}

int MapDelegate::resetRosAll(int &returnFlag)
{
    return communicateNormal->resetRosAll(returnFlag);
}

int MapDelegate::getRosPackageStatus(E_ROS_PACKAGE package, E_ROS_PACKAGE_STATUS &status)
{
    return communicateNormal->getRosPackageStatus(package,status);
}

int MapDelegate::startImuCalibrate(int &returnFlag)
{
    return communicateNormal->startImuCalibrate(returnFlag);
}

int MapDelegate::stopImuCalibrate(int &returnFlag)
{
    return communicateNormal->stopImuCalibrate(returnFlag);
}

int MapDelegate::getCurrentMapName(std::string &mapNameReturn)
{
//   return communicateNormal->getCurrentMapName(mapNameReturn);

    return globalData->getCurrentMapName(mapNameReturn);
}

int MapDelegate::manual_stop(int &returnFlag)
{
    return communicateNormal->manual_stop(returnFlag);
}

int MapDelegate::clear_odomter(int &returnFlag)
{
     return communicateNormal->clear_odomter(returnFlag);
}

int MapDelegate::calibrateVehicle(double xOffset, double yOffset, double rOffset, int &returnFlag)
{
     return communicateNormal->calibrateVehicle(xOffset,yOffset,rOffset, returnFlag);
}

int MapDelegate::setVehicleBorderOffset_rect(double front_offsetIn, double back_offsetIn, double left_offsetIn,
                                             double right_offsetIn, int &returnFlag)
{
     return communicateNormal->setVehicleBorderOffset_rect(front_offsetIn,back_offsetIn,left_offsetIn,right_offsetIn,returnFlag);
}

int MapDelegate::get_vehicle_basic_info(VehicleBasicInfo &basicInfoReturn)
{
//    globalData->lock();
    return globalData->getVehicleBasicInfo(basicInfoReturn);
//    globalData->unlock();
//    return 1;
}

int MapDelegate::get_map_list(std::vector<std::string> &mapNameListReturn)
{
    return communicateNormal->get_map_list(mapNameListReturn);
}

int MapDelegate::getAllPointCloud_translated(std::vector<PointCloudData_3D> &pointCloudOut)
{
//    return communicateNormal->getAllPointCloud_translated(pointCloudOut);

    return globalData->getPointCloud(pointCloudOut);

}

int MapDelegate::getCarBorder(std::vector<VehiclePosition> &carBorderOut)
{
    return communicateNormal->getCarBorder(carBorderOut);
}

int MapDelegate::getCarBorderOffset(std::vector<VehiclePosition> &carBorderOffsetOut)
{
    return communicateNormal->getCarBorderOffset(carBorderOffsetOut);
}

bool MapDelegate::isControllerConnected()
{
    return communicateUpdate->isConnectedStatus();
}
